/**
 * Created by Administrator on 2017/4/14 0014.
 */
import React from "react";
import Util from "../../util/Util"

export default class SendGoods_Item extends React.Component{
    constructor(props){
        super(props);
        this.state={
            text:''
        }
        this.context = {}
    }

    componentWillMount(){
        let contextstring = JSON.stringify(this.context)
        this.context= JSON.parse(contextstring);
    }
    changetext(e){
        let text = e.target.value;
        let teste = /^[0-9]+\.?[0-9]{0,3}$/
        if(!teste.test(text) && text != ''){
            return;
        }
        this.setState({
            text:text
        });

        this.context['goodsId'] = this.props.context.gid;
        this.context['goodsName'] = this.props.context.productName;
        this.context['goodsSize'] = this.props.context.specification;
        this.context['price'] = this.props.context.price;
        this.context['quantity'] = this.props.context.quantity;
        this.context['sendQuantity'] = text
        this.context['remainingQuantity'] = this.props.context.quantity-this.props.context.acceptQuantity
    }


    render(){
        let context = this.props.context;
        let data = Util.dateFormat(context.createDate);
        return (
            <thead>
            <tr className={this.props.index%2==0?"order_list_saleandre_from_trchange":"order_list_saleandre_from_tr"}>
                <td className="order_list_saleandre_from_td order_list_saleandre_from_td_oid">{data}</td>
                <td className="order_list_saleandre_from_td order_list_saleandre_from_td_partb">{context.productName}</td>
                {
                  /*
                  <td className="order_list_saleandre_from_td order_list_saleandre_from_td_product">{context.specification}</td>
                    */
                }
                <td className="order_list_saleandre_from_td order_list_saleandre_from_td_count">{Number(context.price).toFixed(2)}</td>
                <td className="order_list_saleandre_from_td order_list_saleandre_from_td_money">{Number(context.quantity).toFixed(3)}</td>
                <td className="order_list_saleandre_from_td order_list_saleandre_from_td_doit">{Number(context.quantity-context.acceptQuantity).toFixed(3)}</td>
                <td className="order_list_saleandre_from_td order_list_saleandre_from_td_end"><input className="order_from_inputcontext" value={this.state.text}
                onChange={this.changetext.bind(this)}/></td>
            </tr>
            </thead>
        )
    }
}
